package ${pkgName};

<#list imports as im>
import ${im};
</#list>
/**
 * ${className}
 * @author generator
 * @date ${.now?date?string('yyyy年MM月dd日')}
 */
@Service
public class ${className} implements ${serviceEntity.className} {
	
	@Autowired
	private ${daoEntity.className} repo;
	/**
	 * 保存
	 * @param entity
	 */
	public void save(${domainEntity.className} entity){
		this.checkEntity(entity);
		repo.insert(entity);
	}

	/**
	 * 修改
	 * @param entity
	 */
	public void update(${domainEntity.className} entity){
		this.checkEntity(entity);
		repo.update(entity);
	}
	/**
	 * 较验实体
	 * @param entity
	 */
	public void checkEntity(${domainEntity.className} entity){
	
	}
	/**
	 * 删除
	 * @param id
	 */
	public void deleteById(${domainEntity.pkClassName} pk){
		repo.deleteByPK(pk);
	}
	
	/**
	 * 通过id获取
	 * @param id
	 * @return
	 */
	public ${domainEntity.className} findById(${domainEntity.pkClassName} pk){
		return repo.selectByPK(pk);
	}
	/**
	 * 通过非空属性查询
	 * @param ${domainEntity.className}
	 * @return
	 */
	public List<${domainEntity.className}> findByNotNullProps(${domainEntity.className} entity){
		
		SelectStatement<${domainEntity.className}> st = StatementBuilder.buildSelectSelective(entity);
		return repo.selectByStatement(st);
	}
	/**
	 * 通过主键更新非空属性
	 * @param ${domainEntity.className}
	 * @return
	 */
	public void updateNotNullPropsById(${domainEntity.className} entity){
		
		UpdateStatement<${domainEntity.className}> st = StatementBuilder.buildUpdateSelective(entity);
		repo.updateByStatement(st);
	}
	
	/**
	 * 通过实体参数分页查询
	 * @param ${domainEntity.className}.QueryParam
	 * @return
	 */
	public List<${domainEntity.className}> findByQueryParam(${domainEntity.className}.QueryParam queryParam){
		return repo.findByQueryParam(queryParam);
	}
	/**
	 * 通过实体参数统计
	 * @param ${domainEntity.className}.QueryParam
	 * @return
	 */
	public long countByQueryParam(${domainEntity.className}.QueryParam queryParam) {
		return repo.countByQueryParam(queryParam);
	}
	/**
	 * 通过ID集合查询
	 * @param List<${domainEntity.pkClassName}> pks
	 * @return
	 */
	public List<${domainEntity.className}> findByIds(List<${domainEntity.pkClassName}> pks) {
		return repo.selectByPKS(pks);
	}
	/**
	 * 值填充
	 */
	public void fillValues(List<${domainEntity.className}> items, ${domainEntity.className}.ValueField... field) {
		if (items == null || items.isEmpty() || field.length < 1) {
			return;
		}
	}
}
